#In this download, you will find some interview questions to practice your intermediate knowledge of R programming.
#All of the content is based on the R Intermediate tutorial from this website.
#Even if you are not preparing for an interview, these questions can help test your knowledge (perhaps for an upcoming exam, certification, or homework assignment!).

# Question 1: Which of the following is the correct syntax to access the "sales" column from a data frame in R called annual.revenue?

# A. annual.revenue["sales"] <br>
# B. annual.revenue$sales <br>
# C. annual.revenue.sales <br>
# D. annual.revenue[sales] <br>

# Question 1 solution:
# B. annual.revenue$sales

## Question 2: After running the code below, what is the class of the column age?
```{r}
aot <- data.frame(
                  name = c("Eren", "Levi"),
                  age = c(19, 38))
class(aot$age)
```
# A. Character <br>
# B. Integer <br>
# C. Numeric <br>
# D. Vector <br>

# Question 2 solution:
# C. Numeric

# Question 3: What is the output?
```{r}
age <- c(5, 10, 15, 20, 25, 30, 35, 40)
age[age <= 24]
```
# A. 5, 10, 15, 20 <br>
# B. 25, 30, 35, 40 <br>
# C. 15, 20 <br>
# D. 5, 10, 15, 20, 24 <br>

# Question 3 solution:
# A. 5, 10, 15, 20

# Question 4: What data type(s) will the parameter x take in this function? Select all that apply.
```{r}
monthlyrevenue <- function(x) {
  fixed_costs <- 500
  net_profit <- x - fixed_costs

  if (net_profit <= 500) {
    ("In the red")
  } else {
    ("In the green")
  }
}
```

# A. Numeric <br>
# B. Integer <br>
# C. NULL -- the code won't run due to a syntax error. <br>
# D. Character <br>

# Question 4 solution:
# A. Numeric, B. Integer

# Question 5: What will this slice return?
```{r}
#| echo: true
#| results: "hide"
countries <- data.frame(
  country = c("USA", "Canada", "France"),
  foundingyear = c(1776, 1867, 1792),
  population_million = c(340.1, 40.1, 68.29)
)
countries[1:2, ]
```
# A. The entire data frame with all three countries. <br>
# B. Only the first two columns of the data frame. <br>
# C. A syntax error because of incorrect indexing. <br> 
# D. The first two rows of the data frame, showing all columns. <br>

# Question 5 solution:
# D. The first two rows of the data frame, showing all columns. <br>
```{r}
#| echo: false
countries <- data.frame(
  country = c("USA", "Canada", "France"),
  foundingyear = c(1776, 1867, 1792),
  population_million = c(340.1, 40.1, 68.29)
)
countries[1:2, ]
```